#include "TcpServer.hpp"
#include "InetAddr.hpp"
#include "log.hpp"
#include <memory>

std::string defaulthandler(const std::string &word, InetAddrModule::InetAddr &addr)
{
    LogSpace::LOG(LogSpace::LogLevel::DEBUG) << "回调到了defaulthandler";
    std::string s = "haha         #   ";
    s += word;
    LogSpace::LOG(LogSpace::LogLevel::DEBUG) << "回调结束";
    return s;
}

void Usage(std::string proc)
{
    std::cerr << "Usage :" << proc << "service_ip  service_port" << std::endl;
}

int main(int argc,char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(ARGV_ERROR);
    }

    uint16_t port = std::stoi(argv[1]);

    std::unique_ptr<TcpServe> tsvr = std::make_unique<TcpServe>(port,defaulthandler);

    tsvr->Init();
    tsvr->Run();
    
    // std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port,
    // std::bind(&Command::Execute, &cmd, std::placeholders::_1, std::placeholders::_2));

    return 0;
}